using Circus.CodeEditor;
using Circus.CodeEditor.Serialization;
using System;
using System.ComponentModel;
using System.Drawing;
using System.Drawing.Design;
namespace Circus.CodeEditor
{
	[TypeConverter("QWhale.Design.LineStyleConverter, QWhale.Design")]
	[Serializable]
	public class EditLineStyle
	{
		private string name = string.Empty;
		private Color foreColor = EditConsts.DefaultLineStyleForeColor;
		private Color backColor = EditConsts.DefaultLineStyleBackColor;
		private Color penColor = Color.Empty;
		private int imageIndex = -1;
		private int updateCount;
		private LineStyleOptions options = EditConsts.DefaultLineStyleOptions;
		private CodeEditor owner;
		[DefaultValue(""), Description("Gets or sets name of the \"EditLineStyle\".")]
		public virtual string Name
		{
			get
			{
				return this.name;
			}
			set
			{
				if (this.name != value)
				{
					this.name = value;
					this.OnNameChanged();
				}
			}
		}
		[Description("Gets or sets foreground color of the \"EditLineStyle\".")]
		public virtual Color ForeColor
		{
			get
			{
				return this.foreColor;
			}
			set
			{
				if (this.foreColor != value)
				{
					this.foreColor = value;
					this.OnForeColorChanged();
				}
			}
		}
		[Description("Gets or sets background color of the \"EditLineStyle\".")]
		public virtual Color BackColor
		{
			get
			{
				return this.backColor;
			}
			set
			{
				if (this.backColor != value)
				{
					this.backColor = value;
					this.OnBackColorChanged();
				}
			}
		}
		[Description("Gets or sets pen color of the \"EditLineStyle\".")]
		public virtual Color PenColor
		{
			get
			{
				return this.penColor;
			}
			set
			{
				if (this.penColor != value)
				{
					this.penColor = value;
					this.OnPenColorChanged();
				}
			}
		}
		[DefaultValue(-1), Description("Gets or sets the index of the image displayed for the \"EditLineStyle\".")]
		public virtual int ImageIndex
		{
			get
			{
				return this.imageIndex;
			}
			set
			{
				if (this.imageIndex != value)
				{
					this.imageIndex = value;
					this.OnImageIndexChanged();
				}
			}
		}
		[Description("Gets or sets display options for the \"EditLineStyle\"."), Editor("QWhale.Design.FlagEnumerationEditor, QWhale.Design", typeof(UITypeEditor))]
		public virtual LineStyleOptions Options
		{
			get
			{
				return this.options;
			}
			set
			{
				if (this.options != value)
				{
					this.options = value;
					this.OnOptionsChanged();
				}
			}
		}
		
		protected void BeginUpdate()
		{
			this.updateCount++;
		}
		protected void EndUpdate()
		{
			this.updateCount--;
			if (this.updateCount == 0)
			{
				this.Update();
			}
		}
		protected void Update()
		{
			if (this.updateCount == 0 && this.owner != null)
			{
				this.owner.Invalidate();
			}
		}
		protected virtual void OnNameChanged()
		{
		}
		protected virtual void OnForeColorChanged()
		{
			this.Update();
		}
		protected virtual void OnBackColorChanged()
		{
			this.Update();
		}
		protected virtual void OnPenColorChanged()
		{
			this.Update();
		}
		protected virtual void OnImageIndexChanged()
		{
			this.Update();
		}
		protected virtual void OnOptionsChanged()
		{
			this.Update();
		}
		public EditLineStyle()
		{
		}
		public EditLineStyle(CodeEditor owner)
		{
			this.owner = owner;
		}
		public EditLineStyle(CodeEditor owner, string name, Color foreColor, Color backColor, Color penColor, int imageIndex, LineStyleOptions options)
		{
			this.owner = owner;
			this.name = name;
			this.foreColor = foreColor;
			this.backColor = backColor;
			this.penColor = penColor;
			this.imageIndex = imageIndex;
			this.options = options;
		}
		public bool ShouldSerializeForeColor()
		{
			return this.foreColor != EditConsts.DefaultLineStyleForeColor;
		}
		public bool ShouldSerializeBackColor()
		{
			return this.backColor != EditConsts.DefaultLineStyleBackColor;
		}
		public bool ShouldSerializePenColor()
		{
			return this.penColor != Color.Empty;
		}
		public bool ShouldSerializeOptions()
		{
			return this.options != EditConsts.DefaultLineStyleOptions;
		}
		public virtual void Assign(EditLineStyle source)
		{
			this.BeginUpdate();
			try
			{
				this.Name = source.Name;
				this.ForeColor = source.ForeColor;
				this.BackColor = source.BackColor;
				this.PenColor = source.PenColor;
				this.ImageIndex = source.ImageIndex;
				this.Options = source.Options;
			}
			finally
			{
				this.EndUpdate();
			}
		}
		public virtual Color GetBackColor(Color color)
		{
			Color color2 = ((this.options & LineStyleOptions.InvertColors) != LineStyleOptions.None) ? this.foreColor : this.backColor;
			return (color2 != Color.Empty) ? color2 : color;
		}
		public virtual Color GetForeColor(Color color)
		{
			Color color2 = ((this.options & LineStyleOptions.InvertColors) != LineStyleOptions.None) ? this.backColor : this.foreColor;
			return (color2 != Color.Empty) ? color2 : color;
		}
		public virtual void ResetForeColor()
		{
			this.ForeColor = EditConsts.DefaultLineStyleForeColor;
		}
		public virtual void ResetBackColor()
		{
			this.BackColor = EditConsts.DefaultLineStyleBackColor;
		}
		public virtual void ResetPenColor()
		{
			this.PenColor = Color.Empty;
		}
		public virtual void ResetImageIndex()
		{
			this.ImageIndex = -1;
		}
		public virtual void ResetOptions()
		{
			this.Options = LineStyleOptions.InvertColors;
		}
	}
}
